import java.sql.*;
public class Population {
    public static void main(String args[]) {
        Connection con=null;
        Statement sql;
        ResultSet rs;
        try{  Class.forName("com.mysql.jdbc.Driver");
        }
        catch(Exception e){}
        String uri = "jdbc:mysql://localhost:3306/world?useSSL=true&characterEncoding=utf-8";;
        String user ="root";
        String password ="";
        try{
            con = DriverManager.getConnection(uri,user,password);
        }
        catch(SQLException e){ }
        try {
            int pop = 0;
            sql=con.createStatement();
            rs=sql.executeQuery("SELECT * FROM country where Region = 'Middle East'");
            while(rs.next()) {
                pop +=rs.getInt(7);
            }
            System.out.println("世界上的所有中东国家的总人口为"+pop);
            con.close();
        }
        catch(SQLException e) {
            System.out.println(e);
        }
    }
}
